package com.eastfair.messagecenter.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.eastfair.messagecenter.domain.TaskInfo;
import com.eastfair.messagecenter.pending.Task;
import com.eastfair.messagecenter.pending.TaskPendingHolder;
import com.eastfair.messagecenter.service.ConsumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ligang
 */
@Service
public class ConsumeServiceImpl implements ConsumeService {
    @Autowired
    private ApplicationContext context;

    @Autowired
    private TaskPendingHolder taskPendingHolder;

    @Override
    public void consumeSend(List<TaskInfo> taskInfoLists) {
        for (TaskInfo taskInfo : taskInfoLists) {
            Task task = context.getBean(Task.class).setTaskInfo(taskInfo);
            taskPendingHolder.route(taskInfo.getSendChannel()).execute(task);
        }
    }
}
